<?php

function &get_top(&$cheat, &$real)
{
    $array = array();
    foreach ($cheat as $key=>$value)
    {
        $array[$key] = $value + $real[$key];
    }

    return $array;
}

function write_to_file(&$cheat, &$real)
{
    $fp = fopen(FILE_PATH, 'w');

    fwrite($fp, "<?php\n");
    //开始拼装作弊数据
    fwrite($fp, "function &get_cheat_array()\n{\n");
    fwrite($fp, '$array = array('."\n");
    foreach ($cheat as $key=>$value)
    {
        fwrite($fp, '"'.$key.'"=>'.$value.",\n");
    }
    fwrite($fp, ');'."\n");
    fwrite($fp, 'return $array;'."\n");
    fwrite($fp, "}\n");
    //结束拼装作弊数据

    //开始拼装真实数据
    fwrite($fp, "function &get_real_array()\n{\n");
    fwrite($fp, '$array = array('."\n");
    foreach ($real as $key=>$value)
    {
        fwrite($fp, '"'.$key.'"=>'.$value.",\n");
    }
    fwrite($fp, ');'."\n");
    fwrite($fp, 'return $array;'."\n");
    fwrite($fp, "}\n");
    //结束拼装真实数据

    fwrite($fp, "?>\n");

    fclose($fp);

    return true;
}
?>